import { BasicColumn, FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { commonStatusDict, commonStatusDictMap } from '/@/utils/dict';

export const columns: BasicColumn[] = [
  {
    title: '应用名称',
    dataIndex: 'name',
  },
  {
    title: '应用编码',
    dataIndex: 'code',
  },
  {
    title: '排序',
    dataIndex: 'sort',
  },
  {
    title: '默认应用',
    dataIndex: 'active',
    customRender: ({ record }) => {
      const active = record.active;
      const enable = ~~active === 1;
      const color = enable ? 'green' : 'red';
      const text = enable ? '是' : '否';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    dictFormat: commonStatusDictMap,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '应用名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'code',
    label: '应用编码',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'active',
    label: '默认应用',
    component: 'Select',
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: commonStatusDict,
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '应用名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'code',
    label: '应用编码',
    component: 'Input',
    required: true,
  },
  {
    field: 'icon',
    label: '图标',
    component: 'IconPicker',
  },
  {
    field: 'sort',
    label: '排序',
    defaultValue: 10,
    component: 'InputNumber',
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: commonStatusDict,
    },
  },
];
